package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.NewsType;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.INewsTypeService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 不出bug- 么么哒
 * @DESCRIPTION
 * @create 2018/11/14
 */
@Controller
@RequestMapping("/newsType")
public class NewsTypeController {
    @Autowired
    private INewsTypeService newsTypeService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        model.addAttribute ("pageInfo", newsTypeService.query (qo));
        return "/newsType/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(NewsType newsType) {
        JSONResult result = new JSONResult ();
        try {
            newsTypeService.saveOrUpdate (newsType);
        } catch (Exception e) {
            result.mark (e.getMessage ());
        }
        return result;
    }
}
